var express = require("express");
var router = express.Router();
const posService = require("../service/pos")
const Result = require("../models/Result")

router.get("/hello", function (req, res) {
    res.send("pos");
});

router.get("/getPosById", function (req, res) {
    res.json({name: "通过id获取点位", code: 1});
})

router.get("/getPosData", function (req, res) {
    const {roleId} = req.query;
    posService.getPosData(roleId).then((group) => {
        new Result(group, "获取点位信息成功").success(res)
    }).catch((err) => {
        console.log(err)
    })
})

router.get("/getRolePosById", function (req, res) {
    const {roleId, id} = req.query;
    posService.getRolePosById(roleId, id).then((pos) => {
        if (pos) {
            new Result(pos, "获取点位信息成功").success(res)
        } else {
            new Result("没有该点位").fail(res)
        }
    }).catch(err => {
        console.log(err)
    })
})

module.exports = router;